<template>
  <div class="top-right-btn">
  <!--<div class="text-center d-flex align-center justify-space-around">-->
    <el-row>
      <v-tooltip top>
        <template v-slot:activator="{ on, attrs }">
          <v-btn
            icon small plain
            outlined
            color="indigo"
            v-bind="attrs"
            dark
            v-on="on"
            @click="toggleSearch">
            <v-icon>
              mdi-magnify
            </v-icon>
          </v-btn>
        </template>
        <span>{{ showSearch ? '隐藏搜索' : '显示搜索' }}</span>
      </v-tooltip>

      <v-tooltip top>
        <template v-slot:activator="{ on, attrs }">
          <v-btn
            icon small plain
            outlined
            color="indigo"
            v-bind="attrs"
            dark
            v-on="on"
            @click="refresh" style="margin-left: 6px">
            <v-icon>
              mdi-restore
            </v-icon>
          </v-btn>
        </template>
        <span>刷新</span>
      </v-tooltip>

      <!-- todo 显隐列 <v-tooltip top v-if="columns && columns.length > 0">-->
      <v-tooltip top v-if="false">
        <template v-slot:activator="{ on, attrs }">
          <v-btn
            icon small plain
            outlined
            color="indigo"
            v-bind="attrs"
            dark
            v-on="on"
            @click="showColumn" style="margin-left: 6px">
            <v-icon>
              mdi-apps
            </v-icon>
          </v-btn>
        </template>
        <span>显隐列</span>
      </v-tooltip>
    </el-row>
    <el-dialog :title="title" :visible.sync="open" append-to-body>
      <el-transfer
        :titles="['显示', '隐藏']"
        v-model="value"
        :data="columns"
        @change="dataChange"
      ></el-transfer>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "RightToolbar",
  data() {
    return {
      // 显隐数据
      value: [],
      // 弹出层标题
      title: "显示/隐藏",
      // 是否显示弹出层
      open: false,
    };
  },
  props: {
    showSearch: {
      type: Boolean,
      default: true,
    },
    columns: {
      type: Array,
    },
  },
  methods: {
    // 搜索
    toggleSearch() {
      this.$emit("update:showSearch", !this.showSearch);
    },
    // 刷新
    refresh() {
      this.$emit("queryTable");
    },
    // 右侧列表元素变化
    dataChange(data) {
      for (var item in this.columns) {
        const key = this.columns[item].key;
        this.columns[item].visible = !data.includes(key);
      }
    },
    // 打开显隐列dialog
    showColumn() {
      this.open = true;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-transfer__button {
  border-radius: 50%;
  padding: 12px;
  display: block;
  margin-left: 0px;
}
::v-deep .el-transfer__button:first-child {
  margin-bottom: 10px;
}
</style>
